package com.admin.persistence.sys.mapper;

import com.admin.persistence.sys.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author jack
 * @since 2019-05-01
 */
public interface UserMapper extends BaseMapper<User> {

    @Select("SELECT user_.* FROM " +
            "<choose>" +
                "<when test='use==true'>" +
                    "（SELECT * FROM SYS_USER u WHERE u.STATUS='1' ）" +
                "</when>" +
                 "<otherwise>" +
                    "(SYS_USER)" +
                "</otherwise>" +
            "</choose>" +
            "user_ " +
            "INNER JOIN " +
            "SYS_PERSON_USER personUser" +
            "ON " +
            "user_.id = personUser.USER_ID" +
            "INNER JOIN" +
            "(SELECT person_.* FROM SYS_PERSON person_ WHERE 1=1 " +
            "<isNotEmpty property='name'>" +
                "AND person_.NAME LIKE #{name} " +
            "</isNotEmpty>" +
            "<isNotEmpty property='email'>" +
                "AND person_.EMAIL LIKE #{email} " +
            "</isNotEmpty>" +
            "<isNotEmpty property='idCard'>" +
                "AND person_.ID_CARD LIKE #{idCard} " +
            "</isNotEmpty>" +
            "<isNotEmpty property='personId'>" +
            "AND person_.id LIKE #{name} " +
            "</isNotEmpty>"+
            "<isNotNull property='personIds'>" +
            " AND person_.ID in "+
                "<foreach collection='personIds' item='id' open='(' separator=',' close=')'>"+
                    "#{id}"+
                "</foreach>" +
            "</isNotNull>" +
            ")person" +
            "ON" +
            "person.id = perUser.PERSON_ID")
    List<User> queryListByPersonInfo(@Param("personId")String personId, @Param("personIds")List<String> personIds, @Param("name") String name, @Param("emial") String emial, @Param("idCard") String idCard,
                                     @Param("phone") String phone, @Param("uese")boolean uese);

}
